home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / plugin / lights / mesh_light.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-23  |  4.1 KB  |  171 lines

  1. #include "../../lib/Fly3D.h"
  2. #include "lights.h"
  3.  
  4. int mesh_light::get_custom_param_desc(int i,param_desc *pd)
  5. {
  6.     if (pd!=0)
  7.     switch(i)
  8.     {
  9.         case 0:
  10.             pd->type='f';
  11.             pd->data=&illum_radius;
  12.             strcpy(pd->name,"illumradius");
  13.             break;
  14.         case 1:
  15.             pd->type='c';
  16.             pd->data=&color;
  17.             strcpy(pd->name,"color");
  18.             break;
  19.         case 2:
  20.             pd->type='p';
  21.             pd->data=&halopic;
  22.             strcpy(pd->name,"halopic");
  23.             break;
  24.         case 3:
  25.             pd->type='f';
  26.             pd->data=&halosize;
  27.             strcpy(pd->name,"halosize");
  28.             break;
  29.         case 4:
  30.             pd->type='3';
  31.             pd->data=&objmesh;
  32.             strcpy(pd->name,"mesh");
  33.             break;
  34.     }
  35.     return 5;
  36. }
  37.  
  38. void mesh_light::init()
  39. {
  40.     if (objmesh)
  41.         pos=objmesh->pivotpos;
  42. }
  43.  
  44. int mesh_light::step(int dt)
  45. {
  46.     if (directx->mpmode!=FLYMP_SERVER)
  47.     {
  48.         if (halopic!=-1)
  49.             {
  50.             flyengine->excludecollision=flyengine->cam;
  51.             if (flyengine->collision_test(flyengine->bsp,pos,flyengine->cam->pos))
  52.                 {
  53.                 color.w-=dt/200.0f;
  54.                 if (color.w<0.0f)
  55.                     color.w=0.0f;
  56.                 }
  57.             else 
  58.                 {
  59.                 color.w+=dt/200.0f;
  60.                 if (color.w>1.0f)
  61.                     color.w=1.0f;
  62.                 }
  63.             flyengine->excludecollision=0;
  64.             }
  65.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_DYNILLUM,0,&color);
  66.     }
  67.     return 0;
  68. }
  69.  
  70. void mesh_light::draw()
  71. {
  72.     lastdraw=flyengine->cur_frame;
  73.     if (objmesh)
  74.     {
  75.     glPushMatrix();
  76.     glTranslatef(pos.x,pos.y,pos.z);
  77.     objmesh->draw();
  78.     glPopMatrix();
  79.     }
  80.  
  81.     if (halopic==-1 || FP_BITS(color.w)==0) 
  82.         return;
  83.  
  84.     static vector x,y;
  85.     x=flyengine->cam->X*halosize;
  86.     y=flyengine->cam->Y*halosize;
  87.  
  88.     glBlendFunc(GL_ONE,GL_ONE);
  89.     glDepthMask(GL_FALSE);
  90.     glDisable(GL_FOG);
  91.     glDisable(GL_DEPTH_TEST);
  92.     
  93.     glColor3f(color.x*color.w,color.y*color.w,color.z*color.w);
  94.  
  95.     tc->use(halopic);
  96.  
  97.     glBegin(GL_QUADS);
  98.  
  99.     glTexCoord2f(1,0);
  100.     glVertex3f(pos.x+x.x-y.x, pos.y+x.y-y.y, pos.z+x.z-y.z);
  101.  
  102.     glTexCoord2f(1,1);
  103.     glVertex3f(pos.x+x.x+y.x, pos.y+x.y+y.y, pos.z+x.z+y.z);
  104.  
  105.     glTexCoord2f(0,1);
  106.     glVertex3f(pos.x+y.x-x.x, pos.y+y.y-x.y, pos.z+y.z-x.z);
  107.  
  108.     glTexCoord2f(0,0);
  109.     glVertex3f(pos.x-x.x-y.x, pos.y-x.y-y.y, pos.z-x.z-y.z);
  110.  
  111.     glEnd();
  112.  
  113.     glDepthMask(GL_TRUE);
  114.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  115.     if (flyengine->fog) glEnable(GL_FOG);
  116.     glEnable(GL_DEPTH_TEST);
  117. }
  118.  
  119. int mesh_light::message(vector& p,float rad,int msg,int param,void *data)
  120. {
  121.     if (msg==FLYOBJM_STATICILLUM)
  122.         if (radius==0.0f || objmesh==0)
  123.             flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&color);
  124.         else
  125.         {
  126.         vector c=color*0.125f;
  127.         vector m1(radius,radius,radius);
  128.         vector m2(-radius,-radius,-radius);
  129.         
  130.         pos=objmesh->pivotpos+m1;
  131.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  132.  
  133.         flyengine->cur_step++;
  134.         pos=objmesh->pivotpos+m1;
  135.         pos.x=objmesh->pivotpos.x+m2.x;
  136.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  137.  
  138.         flyengine->cur_step++;
  139.         pos=objmesh->pivotpos+m1;
  140.         pos.y=objmesh->pivotpos.y+m2.y;
  141.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  142.  
  143.         flyengine->cur_step++;
  144.         pos=objmesh->pivotpos+m1;
  145.         pos.z=objmesh->pivotpos.z+m2.z;
  146.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  147.  
  148.         flyengine->cur_step++;
  149.         pos=objmesh->pivotpos+m2;
  150.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  151.         
  152.         flyengine->cur_step++;
  153.         pos=objmesh->pivotpos+m2;
  154.         pos.x=objmesh->pivotpos.x+m1.x;
  155.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  156.  
  157.         flyengine->cur_step++;
  158.         pos=objmesh->pivotpos+m2;
  159.         pos.y=objmesh->pivotpos.y+m1.y;
  160.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  161.  
  162.         flyengine->cur_step++;
  163.         pos=objmesh->pivotpos+m2;
  164.         pos.z=objmesh->pivotpos.z+m1.z;
  165.         flyengine->send_bsp_message(flyengine->bsp,pos,illum_radius,FLYOBJM_ILLUM,flyengine->shadows,&c);
  166.  
  167.         pos=objmesh->pivotpos;
  168.         }
  169.     return 0;
  170. }
  171.